<?php



if (!headers_sent())
{
	header("Cache-Control: no-cache, must-revalidate");
	header("Pragma: no-cache");
}

require("dbconn.php");

if (isset($_GET["header"])) $header = $_GET["header"];
if (isset($_GET["hourid"])) $sid = $_GET["hourid"];
if (isset($_GET["subject"])) $subject = $_GET["subject"];
else $subject = "";
if (isset($_GET["docentid"])) $docentid = $_GET["docentid"];
else $docentid = "";
if (isset($_GET["classroom"])) $classroom = $_GET["classroom"];
else $classroom = "";



?>			<table rules="top" cellspacing="0" align="left" valign="top">
<?php
		$QUERY = "
			SELECT plaatsnr, vak, docentid, lokaal
			FROM plaats
			WHERE plaatsnr NOT IN
			(
				SELECT plaatsnr
				FROM studieuurplaats
			)
			AND vak LIKE '$subject%'
			AND docentid LIKE '$docentid%'
			AND lokaal LIKE '$classroom%'
			ORDER BY lokaal ASC, vak ASC, docentid ASC
			LIMIT 0, 15
			";
			
		$week = 52;
		$QUERY = "
			SELECT DISTINCT id, uur, dag
			FROM studieuur
			WHERE id IN
			(
				SELECT studieuur
				FROM studieuurklas
			)
			AND week = '$week'
		";
		//echo $QUERY;
		$resultheader = mysql_query($QUERY);
		$columns = mysql_numrows($resultheader);
		$header = mysql_result($resultheader, $i, "dag") . mysql_result($resultheader, $i, "uur"); // de manier waarop je info uit de db haalt
		$sid = mysql_result($resultheader, $i, "id");
			
			//echo "<a style=\"display: none;\">$QUERY\n</a>\n";
			
		$resultdata = mysql_query($QUERY) or die (mysql_error());
		$rows = mysql_numrows($resultdata);

		if ($rows == 0)
		{
		
		
		
?>				<tr id="<?php print($i . $j); ?>" class="choser_hour">
					<td colspan="4">
						geen resultaten
					</td>
				</tr>
<?php



			if (strlen($subject) == 2 && (strlen($docentid) == 2 || strlen($docentid) == 3) && (strlen($classroom) == 2 || strlen($classroom) == 3))
			{
			
				$QUERY = "
					SELECT plaatsnr, vak, docentid, lokaal
					FROM plaats
					WHERE vak LIKE '$subject%'
					AND docentid LIKE '$docentid%'
					AND lokaal LIKE '$classroom%'
					LIMIT 1
					";
				
				$header = mysql_result($resultheader, $i, "dag") . mysql_result($resultheader, $i, "uur"); // de manier waarop je info uit de db haalt
				$sid = mysql_result($resultheader, $i, "id");
				
				$QUERY = "
					SELECT docentid
					FROM docent
					WHERE docentid IN
					(
						SELECT docentid
						FROM docentcluster
						WHERE cluster IN
						(
							SELECT klas 
							FROM studieuurklas
							WHERE studieuur = '$sid'
						)
					)
				";
					
				$resultdata = mysql_query($QUERY) or die (mysql_error());
				$rows = mysql_numrows($resultdata);
				
				//echo "<a style=\"display: none;\">$QUERY\n</a>\n";
					
				$resultdata = mysql_query($QUERY) or die (mysql_error());
				if (mysql_numrows($resultdata) == 0)
				{

?>				<tr id="<?php print($i . $j); ?>" class="choser_hour">
					<td>
						&nbsp;
					</td>
					<td>
						voeg
					</td>
					<td>
						toe!
					</td>
					<td width="20">
						<a class="actionbutton" onclick="addhour('<?php print("$header"); ?>', '<?php print("$sid"); ?>');"><input type="image" src="pics/addweek.png" /></a>
					</td>
				</tr>
<?php		



				}
				else
				{

				
				
?>				<tr id="<?php print($i . $j); ?>" class="choser_hour">
					<td>
						&nbsp;
					</td>
					<td>
						bestaat
					</td>
					<td>
						al!
					</td>
					<td width="20">
						&nbsp;
					</td>
				</tr>
<?php		



				}
			}
		}
		
		for($j=0; $j < $rows; $j++)
		{
			$datadocentid = mysql_result($resultdata, $j, "docentid");
			
			$header = mysql_result($resultheader, $i, "dag") . mysql_result($resultheader, $i, "uur"); // de manier waarop je info uit de db haalt
			$sid = mysql_result($resultheader, $i, "id");
			
			$QUERY = "
				SELECT docentid
				FROM docent
				WHERE docentid IN
				(
					SELECT docentid
					FROM docentcluster
					WHERE cluster IN
					(
						SELECT klas 
						FROM studieuurklas
						WHERE studieuur = '$sid'
					)
				)
			";
			
			$resultdata2 = mysql_query($QUERY) or die (mysql_error());
			$datacluster = "";
			for ($k=0; $k < mysql_numrows($resultdata2); $k++)
			{
				$datacluster .= mysql_result($resultdata2, $k, "cluster") . " ";
			}
			
			
			
?>				<tr>
					<td id="<?php print($i . $j); ?>">
						<?php print($datadocentid); ?>
					</td>
					<td>
						<?php print($datacluster); ?>
					</td>
					<td>
						<a class="actionbutton" onclick="delplacefromweek('<?php print("$sid"); ?>', '<?php print("$plaatsnr"); ?>')"><img src="pics/delweek.png" /></a>
					</td>
				</tr>
<?php


		}
		
		
		
?>			</table>
